package generics;

import generics.coffee.Coffee;
import generics.coffee.CoffeeGenerator;
import net.mindview.util.CountingGenerator;
import net.mindview.util.Generator;

import java.util.*;

/**
 * @author 杨宇
 * @version 1.0 2016/10/29
 */
public class E13_Generators {
    public static void main(String[] args) {
        List<Coffee> coffeeList = Generators.fill(
                new ArrayList<Coffee>(), new CoffeeGenerator(), 4);
        for(Coffee c : coffeeList)
            System.out.println(c);
        Queue<Integer> iQueue = Generators.fill(
                (Queue<Integer>) new LinkedList<Integer>(),
                new Fibonacci(), 12);
        for(int i : iQueue)
            System.out.print(i + " ");
        System.out.println();
        LinkedList<Character> cLList = Generators.fill(
                new LinkedList<Character>(),
                new CountingGenerator.Character(), 12);
        for(char ch : cLList)
            System.out.print(ch);
        System.out.println();
        Set<Boolean> bSet = Generators.fill(
                new HashSet<Boolean>(),
                new CountingGenerator.Boolean(), 10);
        for(Boolean b : bSet)
            System.out.println(b);
    }
}


class Generators {
    public static <T> List<T> fill(List<T> coll, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++) {
            coll.add(gen.next());
        }
        return coll;
    }
    public static <T> Queue<T> fill(Queue<T> coll, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++) {
            coll.add(gen.next());
        }
        return coll;
    }
    public static <T> Set<T> fill(Set<T> coll, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++) {
            coll.add(gen.next());
        }
        return coll;
    }

    public static <T> LinkedList<T> fill(LinkedList<T> coll, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++) {
            coll.add(gen.next());
        }
        return coll;
    }


}
